package com.maxlen.camunda.utils;

import java.util.Date;

public class DateUtils {

    public static String spendTime(Date start, Date end){
        if(start == null || end == null){
            return null;
        }
        long time = end.getTime() - start.getTime();

        long day=time/(24*60*60*1000);
        //小时
        long hour=(time/(60*60*1000)-day*24);
        //分钟
        long minute=((time/(60*1000))-day*24*60-hour*60);
        //秒，顺便说一下，1秒 = 1000毫秒
        long s=(time/1000-day*24*60*60-hour*60*60-minute*60);
        String result = "";
        if(day != 0){
            result += day + "天 ";
        }
        if(hour != 0){
            result += hour + "小时 ";
        }
        if(minute != 0){
            result += minute + "分 ";
        }
        if(s != 0){
            result += s + "秒 ";
        }
        return result;
    }

}
